package com.base.base

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment

abstract class IFragment(var title: CharSequence = ""): Fragment(){

    protected abstract val layoutRes: Int//布局资源ID

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(layoutRes,container,false)
    }

    /**
     * 当视图创建完成后才去初始化操作 否则用kotlin布局静态加载会报错 findView也会因父布局为空报空指针
     */
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        initLayout(savedInstanceState)
        initListener()
    }

    /**
     * 初始化布局
     */
    protected open fun initLayout(bundle: Bundle?){}

    /**
     * 初始化监听器
     */
    open fun initListener(){}

    /**
     * 重载方法使回调事件能传递到子Fragment
     */
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        for (fragment in childFragmentManager.fragments){ fragment.onActivityResult(requestCode,resultCode,data) }
    }






}